import json
import networkx as nx

class Topo:
    def __init__(self, filename):
        self.ipv4_to_node = {}
        with open(filename) as f:
            obj = json.load(f)
            print(obj)
        self.G = nx.Graph()
        G = self.G
        for node in obj['nodes']:
            G.add_node(node['id'])
            if 'ip' in node:
                G.nodes[node['id']]['ip'] = node['ip']
                self.ipv4_to_node[node['ip']] = node['id']

        for link in obj['links']:
            nodes = list(link.keys())
            G.add_edge(nodes[0], nodes[1], link=link)


    def shortest_path(self, src, dst):
        path = nx.shortest_path(self.G, source=src, target=dst)
        return path
